#!/bin/bash
# generates a directory with a template .tex in it for homework for
# MATH330
DEBUG=false
if $DEBUG
then
    PREFIX="test"
else
    PREFIX="hw"
fi
read HWNUM
HWDIR="$PREFIX$HWNUM"
OF="$PREFIX$HWNUM.tex"
mkdir "$HWDIR"
cd "$HWDIR"
sed 's/∈/\\in/
s/ Z./\\mathbb{Z}./
s/ N./\\mathbb{N}./
s/ Z,/\\mathbb{Z},/
s/ N,/\\mathbb{N},/
s/≤/\\le/
s/≥/\\ge/
s/−/-/' $1 |
awk -v HWNUM=$HWNUM 'BEGIN{NEWTH=3;print "\\documentclass{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage{array}\n\\usepackage{verbatim}\n\\usepackage{fancyhdr}\n\\pagestyle{fancy}\n\\theoremstyle{definition} \\newtheorem{prop}{Proposition}\n\\begin{document}\n\\lhead[]{Joe Tannenbaum - MATH330 - Homework " HWNUM " - \\today}"}
NEWTH==2{print "\n\\begin{prop}[" PROPNUM "]\n" $0 "\n\\end{prop}\n\\begin{proof}\n\n\\end{proof}"; NEWTH=3}
NEWTH==1{PROPNUM=$0; NEWTH=2}
/^ *$/{NEWTH=1}
END{print "\n\\end{document}"}' > "$OF"



